package summary;

/**
 * @Author: 海琳琦
 * @Date: 2022/3/11 10:49
 * https://leetcode-cn.com/problems/integer-break/
 */
public class Title343 {

    /**
     * dp[i]表示整数i拆分后的最大乘积
     * 递推公式：Math.max(i*(i-j), j * dp[i - j])  j属于(1....i)
     * 初始化：dp[1] = 1
     * @param n
     * @return
     */
    public static int integerBreak(int n) {
        int[] dp = new int[n + 1];
        //初始化
        dp[1] = 1;
        for (int i = 2; i <= n; i++) {
            for (int j = 1; j <= i - 1; j++) {
                dp[i] = Math.max(dp[i], Math.max(j * (i - j), j * dp[i - j]));
            }
        }
        return dp[n];
    }

    public static void main(String[] args) {
        integerBreak(2);
    }
}
